/**
 * 
 */
package defi5;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
 * @author Logan
 *
 */
public class Debrouillage {


	public static void transforme(BufferedImage img_src, BufferedImage img_dst, int w, int h) {
		for (int i=0; i<w; ++i)
			for (int j=0; j<h; ++j) {
				Point p = Boulanger.boulanger(i,j,w,h);
				img_dst.setRGB(p.x,p.y,img_src.getRGB(i,j));
			}
	}

	public static Point transformePoint(int w, int h, Point p, int nbFois) {
		for(int i = 0; i<nbFois; i++) {
			p = Boulanger.boulanger(p.x, p.y, w, h);
		}

		return p;
	}

	public static void main (String[] args) throws IOException {

		BufferedImage img = ImageIO.read(new File("image.png"));
		int w = img.getWidth();
		int h = img.getHeight();
		BufferedImage img2 = new BufferedImage(img.getWidth(),img.getHeight(),img.getType());



		int nbAFaire = 186593 - 33246;
		

		Point p1 = new Point(306,472);
		Point current = transformePoint(w,h,p1, nbAFaire);
		img2.setRGB(current.x,current.y,img.getRGB(p1.x,p1.x));
		//Point current = transformePoint(w,h,p1, nbAFaire);

		System.out.println("test");



		//int tmp = 1;
		Point p2 = Boulanger.boulanger(p1.x, p1.y, w, h);
		current = transformePoint(w,h,p2, nbAFaire);
		img2.setRGB(current.x,current.y,img.getRGB(p2.x,p2.x));
		p2.ok=true;

		while(!p1.equals(p2)) {
			//tmp ++;
			p2 = Boulanger.boulanger(p2.x, p2.y, w, h);
			current = transformePoint(w,h,p2, nbAFaire);
			img2.setRGB(current.x,current.y,img.getRGB(p2.x,p2.x));
			//System.out.println(tmp);
		}


		System.out.println("test2");

		ImageIO.write(img2,"png",new File("out.png"));
		System.out.println("Fichier cree");
	}

}

